﻿Namespace Web
    Partial Public Class Document

        Public Property DataCombo As OpcioCombo
            Get
                Dim Data As Date = New Date(DataInicial.ToUniversalTime().Year, DataInicial.ToUniversalTime.Month, 1)
                Dim OpcioCombo As OpcioCombo = (From o As OpcioCombo In OpcionsDatesHoraris.Llista Where o.Id = Data).FirstOrDefault()
                If OpcioCombo Is Nothing Then
                    Return New OpcioCombo(Data, Data.ToString("MMMM yyyy"))
                Else
                    Return OpcioCombo
                End If
            End Get
            Set(value As OpcioCombo)
                DataInicial = Date.SpecifyKind(value.Objecte, DateTimeKind.Utc)
                DataFinal = DataInicial.AddMonths(1).AddDays(-1)
                Titol = StringLibrary.Horari & " " & value.Nom
            End Set
        End Property

        Public ReadOnly Property strDataInicial As String
            Get
                Return DataInicial.ToUniversalTime.ToString("MMMM yyyy")
            End Get
        End Property

        Private Sub OnDataInicialChanged()
            If DataInicial.Kind <> DateTimeKind.Utc Then                Dim data As DateTime = Date.SpecifyKind(DataInicial, DateTimeKind.Utc)                DataInicial = New Date()
                DataInicial = data
            End If

            RaisePropertyChanged("strDataInicial")
            RaisePropertyChanged("DataCombo")
        End Sub

        Private Sub OnDataFinalChanged()
            If DataFinal.Kind <> DateTimeKind.Utc Then                Dim data As DateTime = Date.SpecifyKind(DataFinal, DateTimeKind.Utc)                DataFinal = New Date()
                DataFinal = data
            End If
        End Sub
    End Class
End Namespace
